package funcs

import (
	"os"
	"time"
	"net/http"
	"io"
	"fmt"
)
func (f FileUtils)Download(url string,destPath string)  error {
	newFile, err := os.Create(destPath)
	if err != nil {
		fmt.Errorf("create download file failed: %v", err)
		return err
	}
	defer newFile.Close()
	client := http.Client{Timeout: 900 * time.Second}
	resp, err := client.Get(url)
	if err != nil {
		fmt.Errorf("Download file failed: %v", err)
		return err
	}
	defer resp.Body.Close()
	_, err = io.Copy(newFile, resp.Body)
	return err
}
